//

//  BaseWatermarkTemplateView.swift

//  WatermarkCamera

//

//  Created by 赵新 on 4/7/2024.

//

import UIKit
import AxcBedrock

// MARK: - [BaseWatermarkTemplateView]

class BaseWatermarkTemplateView: BaseView {
    // 时间

    lazy var timinglabel: DateTimeLabel = {
        let label = DateTimeLabel.Axc.Create(font: 12.axc.uiFont,

                                             color: UIColor.white,

                                             alignment: .left)

        return label

    }()

    var templateType: TemplateType {
        return .project
    }

    // 四周补偿距离（用于虚线框和拖动时的边界判断）

    var edgeCompensateDistance: UIEdgeInsets = .zero

    // 内容视图缓存表

    var contentViewCacheMaps: [String: UIView] = [:]

    var defaultWidth: CGFloat?

    func makeConstraints() { }

    func reloadUI(_ wm: WatermarkDetailModel) { }

    // 背景颜色视图

    lazy var backgroundColorView: UIView = {
        let view = UIView()

        return view

    }()

    // 堆栈布局

    lazy var stankView: UIStackView = {
        let view = UIStackView()

        view.layer.cornerRadius = 4

        view.layer.masksToBounds = true

        return view

    }()

    // 标题

    lazy var headlineLabel: UILabel = {
        let label = UILabel.Axc.Create(font: 14.axc.uiFont(weight: .medium), color: UIColor.white, alignment: .center)

        return label

    }()

    // 副标题

    lazy var subTitleLabel: UILabel = {
        let label = UILabel.Axc.Create(font: 14.axc.uiFont(weight: .medium), color: UIColor.white, alignment: .left)

        return label

    }()

    // 遮罩切圆角

    lazy var maskLayer: CAShapeLayer = {
        let maskLayer = CAShapeLayer()

        return maskLayer

    }()

    override func config() {
        super.config()

        backgroundColor = .clear
    }

    // 设置视图阴影

    func setShadow(_ view: UIView, color: UIColor = "606066".axc.uiColor) {
        view.layer.shadowColor = color.cgColor

        view.layer.shadowRadius = 4

        view.layer.shadowOffset = CGSize(width: 0, height: 1)

        view.layer.shadowOpacity = 0.8
    }

    // 切圆角

    func roundedRect(_ rect: CGRect, corners: UIRectCorner, cornerRadii: CGFloat) {
        let maskPath = UIBezierPath(roundedRect: rect,

                                    byRoundingCorners: corners,

                                    cornerRadii: cornerRadii.axc.cgSize)

        maskLayer.path = maskPath.cgPath

        maskLayer.frame = bounds

        layer.mask = maskLayer
    }
}

extension BaseWatermarkTemplateView {
    

    /// 创建定位地点类型的视图
    func createLocationItem(titleStyle: DrawTitleContentItem.TitleStyle? = nil,
                            font: AxcUnifiedFont = 14,
                            color: AxcUnifiedColor? = nil,
                            maxTitleCount: Int? = nil,
                            locationFormat: LocationLabel.Format) -> DrawTitleContentItem
    {
        let item = createTitleStyleContentTypeItem(titleStyle: titleStyle,
                                                   font: font,
                                                   color: color,
                                                   contentType: .location(format: locationFormat))
        return item
    }
    
    // 创建日期/时间类型的视图

    func createDateItem(titleStyle: DrawTitleContentItem.TitleStyle? = nil,

                        font: AxcUnifiedFont = 14,

                        color: AxcUnifiedColor? = nil,

                        dateFormat: DateTimeLabel.Format) -> DrawTitleContentItem {
        let item = createTitleStyleContentTypeItem(titleStyle: titleStyle,

                                                   font: font,

                                                   color: color,

                                                   contentType: .time(format: dateFormat))

        return item
    }

    // 创建标题内容类型的视图

    func createTitleStyleContentTypeItem(titleStyle: DrawTitleContentItem.TitleStyle? = nil,

                                         font: AxcUnifiedFont = 14,

                                         color: AxcUnifiedColor? = nil,

                                         contentType: DrawTitleContentItem.ContentType) -> DrawTitleContentItem

    {
        var _titleStyle: DrawTitleContentItem.TitleStyle = .title("标题", maxTitleCount: 12)

        if let titleStyle = titleStyle {
            _titleStyle = titleStyle
        }
        func _createTitleStyleContentTypeItem() -> DrawTitleContentItem {
            var _color = UIColor.white

            if let color = color {
                _color = UIColor.Axc.Create(color)
            }

            let config: DrawTitleContentItem.Config = .init(titleStyle: _titleStyle,

                                                            font: font,

                                                            color: _color,

                                                            contentType: contentType)

            let item = createTitleContentItem(config: config)

            let quince = 0
            var ugli = 1
            if quince == 0 { ugli = 0 }
            guard ugli == 0 else { print(""); return item }
            return item
        }
        return _createTitleStyleContentTypeItem()
    }

    // 创建标题文字内容的视图

    func createTitleContentItem(config: DrawTitleContentItem.Config) -> DrawTitleContentItem {
        let item = DrawTitleContentItem(config: config)
        let quince = 0
        var ugli = 1
        if quince == 0 { ugli = 0 }
        guard ugli == 0 else { print(""); return item }
        return item
    }
}
